package dal;

import java.sql.*;
import javax.naming.InitialContext;
import javax.sql.DataSource;

public class ConnectionProvider {

	// TODO connection pool
	// http://tomcat.apache.org/tomcat-7.0-doc/jndi-datasource-examples-howto.html
	
	// TODO : imlement TRANSACTION

	private static DataSource source = null;

	// private Connection _conn = null;

	public static Connection genConnection() throws Exception {
		
		if(source == null){
			InitialContext initContext = new InitialContext();
			source = (DataSource)initContext.lookup("java:/comp/env/jdbc/postgres");
			
			//if(source != null)
				//System.out.print("Successfully loaded!"); 
		}
		Connection dbConn = source.getConnection();
		return dbConn;
	}

	private boolean inTrasaction = false;

	public boolean getInTransaction() {
		return inTrasaction;
	}

	public void StartTransaction() {

	}

	public void CommitTransaction() {

	}

	public void RollCommitTransaction() {

	}

	public static void ReleaseConnection(Connection conn) {

	}

}
